﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TPLOAWebService.Models
{
    public class LOARepository : ILOARepository
    {
        public IEnumerable<LOA> GetAll()
        {
            return TPLOADBManager.GetAllLOA().Cast<LOA>();
        }

        public LOA Get(int id)
        {
            return TPLOADBManager.GetLOAByID(id);
        }

        public IEnumerable<LOA> GetLOAByAdminNo(string id)
        {
            return TPLOADBManager.GetLOAByAdminNo(id).Cast<LOA>();
        }

        public IEnumerable<LOA> GetLOAByCourseCode(string id)
        {
            return TPLOADBManager.GetLOAByCourseCode(id).Cast<LOA>();
        }

        public LOA Add(LOA item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.InsertLOA(item) == 0)
            {
                return null;
            }
            else
            {
                return item;
            }
        }

        public void Remove(int id)
        {
            TPLOADBManager.DeleteLOA(id);
        }

        public bool Update(LOA item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.UpdateLOA(item) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}